package com.lucifer.hawkeye.ai.domain.nl2sql.type;

import lombok.Getter;
import org.apache.commons.collections4.map.UnmodifiableMap;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author lucifer
 * @date 2025/4/1 17:00
 */
@Getter
public enum TrainType {

    DDL("DDL","DDL语句"),

    SQL("SQL","SQL语句"),

    DOC("DOC","文档");

    private final String code;
    private final String name;




    private static final Map<String, TrainType> CODE_MAPPING = UnmodifiableMap.unmodifiableMap(
            Arrays.stream(TrainType.values()).collect(Collectors.toMap(TrainType::getCode, Function.identity()))
    );

    public static boolean check(String code) {
        return CODE_MAPPING.containsKey(code);
    }

    TrainType(@NotNull String code, @NotNull String name) {
        this.code = code;
        this.name = name;
    }


    public static TrainType codeOf(String code) {
        return Optional.ofNullable(code).map(CODE_MAPPING::get).orElse(TrainType.DDL);

    }
}
